<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>计算文件的 sha1 散列值</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.setlocale.html">« setlocale</a></li>
      <li style="float: right;"><a href="function.sha1.html">sha1 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>计算文件的 sha1 散列值</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.sha1-file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sha1_file</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">sha1_file</span> &mdash; <span class="dc-title">计算文件的 sha1 散列值</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sha1-file-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sha1_file</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$binary</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="simpara">
   使用 <a href="http://www.faqs.org/rfcs/rfc3174" class="link external">&raquo;&nbsp;美国安全散列算法 1</a> 计算
   <code class="parameter">filename</code> 指定的文件的 sha1 散列值，并返回该散列值。
   该散列值为 40 字符长度的十六进制数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sha1-file-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       要散列的文件的文件名。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">binary</code></dt>

     <dd>

      <p class="para">
       为 <strong><code>true</code></strong> 时，返回 20 字符长度的原始二进制格式摘要。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sha1-file-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功返回字符串，否则返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sha1-file-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4807">
    <p><strong>示例 #1 <span class="function"><strong>sha1_file()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">'/home/Kalle/myproject/*.php'</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$ent</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">is_dir</span><span style="color: #007700">(</span><span style="color: #0000BB">$ent</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$ent&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'&nbsp;(SHA1:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">sha1_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$ent</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">')'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sha1-file-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.sha1.html" class="function" rel="rdfs-seeAlso">sha1()</a> - 计算字符串的 sha1 散列值</span></li>
    <li class="member"><span class="function"><a href="function.md5-file.html" class="function" rel="rdfs-seeAlso">md5_file()</a> - 计算指定文件的 MD5 散列值</span></li>
    <li class="member"><span class="function"><a href="function.crc32.html" class="function" rel="rdfs-seeAlso">crc32()</a> - 计算一个字符串的 crc32 多项式</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>